//
//  AppDelegate.m
//  WSLAPP
//
//  Created by 王双龙 on 15/10/14.
//  Copyright (c) 2015年 WSL. All rights reserved.
//

#import "AppDelegate.h"
#import "wslRootViewController.h"
#import "wslNavigationController.h"
//#import "UMSocial.h"
//#import "UMSocialQQHandler.h"
//#import "UMSocialWechatHandler.h"

@interface AppDelegate ()<UIAlertViewDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIWindow * window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    window.backgroundColor =  [UIColor colorWithRed:255/255.0f green:192/255.0f blue:0/255.0f alpha:1.0f];
    self.window = window;
    [self.window makeKeyAndVisible];
    //让app支持接受远程控制事件
    //设置app支持接受远程控制事件，其实就是在dock中可以显示应用程序图标，同时点击该图片时，打开app
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    //第三方应用打开本应用启动
    if(launchOptions[UIApplicationLaunchOptionsURLKey] != nil){
        [self application:application handleOpenURL:launchOptions[UIApplicationLaunchOptionsURLKey]];
    }
    // iOS8以上版本注册通知权限
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]];
    }
    wslRootViewController * rootVc = [[wslRootViewController alloc] init];
    // 设置友盟的Key
//    [UMSocialData setAppKey:@"507fcab25270157b37000010"];
//    //设置分享到QQ/Qzone的应用Id，和分享url 链接
//    [UMSocialQQHandler setQQWithAppId:@"1104927471" appKey:@"DCM5IBTYED0HpxTZ" url:@"http://www.henau.edu.cn"];
//    //设置支持没有客户端情况下使用SSO授权
//    [UMSocialQQHandler setSupportWebView:YES];
//    //设置微信AppId、appSecret，分享url
//    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.henau.edu.cn"];
    self.window.rootViewController = rootVc;
    return YES;
}

//处理后台传递给我们的信息，用于音乐
- (void)remoteControlReceivedWithEvent:(UIEvent *)event{
    if (event.type == UIEventTypeRemoteControl) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"songControlNotification" object:self userInfo:@{@"subtype":@(event.subtype)}];
    }
}


#pragma mark - 第三方登录回调方法
- (void)applicationWillResignActive:(UIApplication *)application {
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

- (void)applicationWillTerminate:(UIApplication *)application {
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{
    return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options{
    UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"分享" message:[url host] delegate:self cancelButtonTitle:nil otherButtonTitles:@"分享完成", nil];
    [alertView show];
    return YES;
}
                              
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSURL * url = [NSURL URLWithString:@"wsl123456://success"];
    [[UIApplication sharedApplication] openURL:url options:nil completionHandler:^(BOOL success) {
    }];
}

@end
